/**
 * 
 */
package com.edocbase.desktop.lightweight.widgets.richeditor.commands.base;

import com.edocbase.desktop.lightweight.widgets.richeditor.HTMLDocument2;
import com.edocbase.desktop.lightweight.widgets.richeditor.IHTMLSelectionObject;
import com.edocbase.desktop.lightweight.widgets.richeditor.RichEditor;
import com.edocbase.desktop.lightweight.widgets.richeditor.TextRange;
import com.edocbase.desktop.lightweight.widgets.richeditor.commands.DocumentCommand;

public class GetSelectedTextCommand extends DocumentCommand {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8225226660075398488L;

	/* (non-Javadoc)
	 * @see com.edocbase.desktop.lightweight.widgets.richeditor.commands.DocumentCommand#getCommandIdentifier()
	 */
	@Override
	public String getCommandIdentifier() {
		return null;
	}
	protected boolean trackCommand() {
		return false;
	}
	@Override
	public void execute() {
		RichEditor editor = invoker.getActiveEditor();
		HTMLDocument2 htmlDoc = editor.getHTMLDocument();
		try{
			IHTMLSelectionObject htmlSelection = htmlDoc.getSelection();
			TextRange range = htmlSelection.createRange();
			String text = range.getText();
			returnObject = text;
			
			htmlSelection.dispose();
			range.dispose();
		}finally{
			htmlDoc.dispose();
		}
	}
	
	
}
